//
//  GoodsViewController.m
//  Leisure
//
//  Created by xalo on 16/6/30.
//  Copyright © 2016年 Hero. All rights reserved.
//

#import "GoodsViewController.h"

@interface GoodsViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic,strong)NSMutableArray *dataSource;
@end

@implementation GoodsViewController
- (NSMutableArray *)dataSource{
    if (!_dataSource) {
        _dataSource = [[NSMutableArray alloc]init];
    }
    return _dataSource;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerNib:[UINib nibWithNibName:@"GoodsCell" bundle:nil] forCellReuseIdentifier:@"goods_cell"];
    [RequestManager fetchDataWithUrl:kGoodsUrl parameter:@{} mehtod:@"POST" compelet:^(NSData *data) {
        NSDictionary *bigDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

        for (NSDictionary *smallDic in bigDic[@"data"][@"list"]) {
            GoodsModel *model = [[GoodsModel alloc]init];
            [model setValuesForKeysWithDictionary:smallDic];
            [self.dataSource addObject:model];
            
        }
        
    } updata:^{
        [self.tableView reloadData];
    }];
    
    
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    GoodsCell *cell = [tableView dequeueReusableCellWithIdentifier:@"goods_cell" forIndexPath:indexPath];
    
    [cell setCellWithModel:self.dataSource[indexPath.row]];
    

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 200;
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
